<?php
/**
 * ArchivePress "Right Now" Dashboard widget
 *
 * @author University of London Computer Centre
 * @version 1.4.0 - Release Candidate 2
 * @package ArchivePress
 * @subpackage widgets
 * @global ArchivePress $ArchivePress
 */

global $ArchivePress;

// get blogs
$blogs = $ArchivePress->getBlogs();
$totBlogs = $blogs["total"];
$activeBlogs = $blogs["active"];

// get fetched posts
$posts = $ArchivePress->getPosts();

// get fetched comments
$comments = $ArchivePress->getComments();

// get authors
$authors = $ArchivePress->getAuthors();

// get last blog fetched
$lastFetched = $ArchivePress->getLastFetched("blog");
if(array_key_exists("blog", $lastFetched)){
    $lastBlog = $lastFetched["blog"];
    $lastTime = $lastFetched["datetime"];
} else {
    $lastBlog = "";
    $lastTime = 0;
}

// get next blog to fetch
$nextToFetch = $ArchivePress->getNextToFetch("blog");
if(array_key_exists("blog", $nextToFetch)){
    $nextBlog = $nextToFetch["blog"];
    $nextTime = $nextToFetch["datetime"];
} else {
    $nextBlog = "";
    $nextTime = 0;
}

// get last comment fetched
$lastFetched = $ArchivePress->getLastFetched("comment");
if(array_key_exists("blog", $lastFetched)){
    $lastComment = $lastFetched["blog"];
    if(strlen($lastComment) > 28)
        $lastComment = substr($lastComment,0,25)."...";
    $lastCTime = $lastFetched["datetime"];
} else {
    $lastComment = "";
    $lastCTime = 0;
}

// get next comment to fetch
$nextToFetch = $ArchivePress->getNextToFetch("comment");
if(array_key_exists("blog", $nextToFetch)){
    $nextComment = $nextToFetch["blog"];
    if(strlen($nextComment) > 28)
        $nextComment = substr($nextComment,0,25)."...";
    $nextCTime = $nextToFetch["datetime"];
} else {
    $nextComment = "";
    $nextCTime = 0;
}

// SHOW THEM inside the Dashboard Widget
echo'<p class="sub">'.__("At a Glance",ARCHIVEPRESS).'</p>
    <div class="table">
        <table>
        <tbody>
            <tr class="first">
                <td class="first b"><a href="admin.php?page=archivepress/pages/edit-posts.php">'.$totBlogs.'</a></td>
                <td class="t"><a href="admin.php?page=archivepress/pages/edit-posts.php">'.__("Blogs",ARCHIVEPRESS).'</a> <a class="active" style="color:green;" href="admin.php?page=archivepress/pages/edit-posts.php&amp;post_status=active">('.$activeBlogs.' '.__("active",ARCHIVEPRESS).')</a></td>
            </tr>
            <tr>
                <td class="first b"><a href="edit.php">'.$posts.'</a></td>
                <td class="t"><a href="edit.php">'.__("Posts added",ARCHIVEPRESS).'</a></td>
            </tr>

            <tr>
                <td class="first b"><a href="edit-comments.php">'.$comments.'</a></td>
                <td class="t"><a href="edit-comments.php">'.__("Comments added",ARCHIVEPRESS).'</a></td>
            </tr>
            <tr>
                <td class="first b"><a href="admin.php?page=archivepress/pages/authors.php">'.$authors.'</a></td>
                <td class="t"><a href="admin.php?page=archivepress/pages/authors.php">'.__("Authors added",ARCHIVEPRESS).'</a></td>
            </tr>
        </tbody>
        </table>
    </div>
    <div class="versions">
    <br />
    <p class="sub">'.__("Blog: ",ARCHIVEPRESS).'</p>
        <p>'.__("Last fetched: ",ARCHIVEPRESS).'<span class="b">'.$ArchivePress->cleanOutput($lastBlog).'</span> <span class="b">(<a>'.mysql2date('F jS, Y @ H:i',$lastTime).'</a>)</span></p>
        <p>'.__("Next to fetch: ",ARCHIVEPRESS).'<span class="b">'.$ArchivePress->cleanOutput($nextBlog).'</span> <span class="b">(<a>'.date('F jS, Y @ H:i',$nextTime).'</a>)</span></p>
    <br />
    <p class="sub">'.__("Comments: ",ARCHIVEPRESS).'</p>
        <p>'.__("Last fetched: ",ARCHIVEPRESS).'<span class="b">'.$ArchivePress->cleanOutput($lastComment).'</span> <span class="b">(<a>'.mysql2date('F jS, Y @ H:i',$lastCTime).'</a>)</span></p>
        <p>'.__("Next to fetch: ",ARCHIVEPRESS).'<span class="b">'.$ArchivePress->cleanOutput($nextComment).'</span> <span class="b">(<a>'.date('F jS, Y @ H:i',$nextCTime).'</a>)</span></p>
        <br class="clear" />
    </div>
';

?>